﻿function stateChanged() {
    if (xmlhttp.readyState == 4) {
        if (receiveid == "search") {
            try {
                if (xmlhttp.responseText != '') {
                    var fill = eval('(' + xmlhttp.responseText + ')');
                    document.getElementById(receiveid).innerHTML = fillSearch_Book(fill);
                }
                else {
                    document.getElementById(receiveid).innerHTML = "<center class='green'><span>No. record found.</span></center>";
                }

            } catch (e) {
                document.getElementById(receiveid).innerHTML = "<center class='red'><span>Error : Server seems to be very busy.Please try after some time. </span></center>";
            }
        }
        else {
            document.getElementById(receiveid).innerHTML = xmlhttp.responseText;
        }
    } else {
            document.getElementById(receiveid).innerHTML = "<div align='center'><img src='images/loading.gif' /></div>";
    }
    }
    function Get_SearchBook(tval,str) {
        var _currentPage = 1;
        var maxRecord = 20;
        if (document.getElementById('_currentPage')) {
            _currentPage = document.getElementById('_currentPage').value;
        }
        var recid = "search"
        if (tval == "CreateExcel") {
            recid = "createexcel"
        }
        senddata_post('Rpt_nAccesisonRegister', 'T='+tval+str + '&page=' + _currentPage + '&maxrecord=' + maxRecord, recid);
    }

    function hideunhide(val) {
        for (var i = 1; i <= 6; i++) {
            if (val == i) { document.getElementById('divsearch' + i).className = 'inline'; }
            else { document.getElementById('divsearch' + i).className = 'none'; }
        }
    }

    function printreceipt() {
        var currentTime = new Date()
        var month = currentTime.getMonth() + 1
        var day = currentTime.getDate()
        var year = currentTime.getFullYear()

        var wn = window.open('Accession Register', '', 'width=900,height=900,scrollbars=1');
        var str = "";
        str += "<html><head><title>Print Preview::Accession Register</title></head><body><div> <b> ACCESSION REGISTER </b> </center> </div> <div> Today Date = " + month + "/" + day + "/" + year + " </div> <table cellpadding='5' cellspacing='0' border='1px' cellpadding='0'  style='border-color:Black; border-collapse:collapse'>" + document.getElementById('result').innerHTML + "</table></body></html>"
        wn.document.write(str);
        wn.print();

    }
    function fillSearch_Book(data) {
        if (data.length > 0) {
            var str = ""
            str += '<div id="createexcel"><a href="javascript:void(0)" onclick=" get_book(\'excel\')">Create Excel</a></div><table id="result" class="tblist" style="margin:0px">';
            str += '<tr>';
            str += '<th>S.No</th>';
            str += '<th>Acession Number</th>';
            str += '<th>Author</th>';
            str += '<th>Book Title</th>';
            str += '<th>Edition</th>';
            str += '<th>Publisher</th>';
            str += '<th>Publication Year</th>';
            str += '<th>Pages</th>';
            str += '<th>Volume</th>';
            str += '<th>Supplier</th>';
            str += '<th>Bill No.</th>';
            str += '<th>Bill Date</th>';
            str += '<th>Cost</th>';
            str += '<th>Renew Date</th>';
            str += '<th>Purchase Year</th>';
            str += '<th>Classification No.</th>';
            str += '<th>Book Entry Employee Name</th>';
            str += '<th style="width: 200px">Book Location</th>';
            str += '</tr>';
            var _currentPage = 1;
            if (document.getElementById('_currentPage')) {
                _currentPage = document.getElementById('_currentPage').value;
            }
            paging({ "totRecord": "" + data[0].maxcount + "", "fnName": "get_book();", "maxShowRecord": "" + data[0].maxrecord + "", "noOfLink": "5", "id": ["bPaging", "tPaging"] });
            for (var i = 0; i < data.length; i++) {
                str += "<tr>"
                str += "<td>" + ((20 * (parseInt(_currentPage)-1)) +(parseInt(i)+1))+"</td>";
                str += "<td>" + data[i].accessionno + "</td>";
                str += "<td>" + data[i].author + "</td>";
                str += "<td>" + data[i].booktitle + "</td>";
                str += "<td>" + data[i].edition + "</td>";
                str += "<td>" + data[i].Publicationname + "</td>";
                str += "<td>" + data[i].publicationyear + "</td>";
                str += "<td>" + data[i].pages + "</td>";
                str += "<td>" + data[i].bookvol + "</td>";
                str += "<td></td>";
                str += "<td>" + data[i].billno + "</td>";
                str += "<td>" + data[i].billdate + "</td>";
                str += "<td>" + data[i].price + "</td>";
                str += "<td>" + data[i].renewdate + "</td>";
                str += "<td>" + data[i].purchaseyear + "</td>";
                str += "<td>" + data[i].cl + "</td>";
                str += "<td>" + data[i].acname + "</td>";
                str += "<td>" + data[i].bklocation + "</td>";
                str += "</tr>"
            }
            str += "</table>";
        }
        else { 
          str+="<center><span class='green'>No record found.</span>"
        }
       return str;
   }

